//
//  BVCommunityViewController.m
//  XiangYu
//
//  Created by YYKJ on 2017/8/5.
//  Copyright © 2017年 YYKJ. All rights reserved.
//  动态详情

#import "BVCommunityDetailViewController.h"
#import "DemoVC7Model.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
#import "BVSportsSliderView.h"
#import "BVCommunityDetailCell1.h"
#import "BVCommunityDetailCell2.h"
#import "BVBottomView.h"

#define BUY_MYBASKLIST_TAB_CELL1 @"BVCommunityDetailCell1"
#define BUY_MYBASKLIST_TAB_CELL2 @"BVCommunityDetailCell2"
@interface BVCommunityDetailViewController ()<UITableViewDelegate ,UITableViewDataSource>

@property (nonatomic ,strong) UITableView      *tabView;
@property (nonatomic, strong) NSMutableArray   *modelsArray;

@end

@implementation BVCommunityDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationItem setTitle:@"动态详情"];
    
    [self creatModelsWithCount:20];
    [self.view addSubview:self.tabView];
    [self setBottomView];
    
}

#pragma mark -
#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 2;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        return 40;
    }else{
        return 0.1;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        BVSportsSliderView *lider = [[BVSportsSliderView alloc]initWithFrame:CGRectMake(0,0, ScreenW, 40) titleArr:@[@"分享",@"评论",@"赞"]];
        lider.btnClick = ^(NSInteger index) {
            
        };
        return lider;
    }else{
        UIView *view = [[UIView alloc]init];
        return view;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return section == 0 ? 1:10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        DemoVC7Model *demoVC14Modelodel = self.modelsArray[indexPath.row];
        return [self.tabView cellHeightForIndexPath:indexPath model:demoVC14Modelodel keyPath:@"model" cellClass:[BVCommunityDetailCell1 class] contentViewWidth:ScreenW];
    }else{
        return 100;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        BVCommunityDetailCell1 *cell = [tableView dequeueReusableCellWithIdentifier:BUY_MYBASKLIST_TAB_CELL1];
        cell.model = self.modelsArray[indexPath.row];
        return cell;
    }else{
        BVCommunityDetailCell2 *cell = [tableView dequeueReusableCellWithIdentifier:BUY_MYBASKLIST_TAB_CELL2];
        return cell;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

-(UITableView *)tabView{
    if (!_tabView) {
        _tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH-64) style:UITableViewStylePlain];
        [_tabView setDelegate:self];
        [_tabView setDataSource:self];
        [_tabView setBackgroundColor:[UIColor clearColor]];
        [_tabView setShowsVerticalScrollIndicator:NO];
        [_tabView setRowHeight:50];
        [_tabView registerClass:[BVCommunityDetailCell1 class] forCellReuseIdentifier:BUY_MYBASKLIST_TAB_CELL1];
        [_tabView registerClass:[BVCommunityDetailCell2 class] forCellReuseIdentifier:BUY_MYBASKLIST_TAB_CELL2];
    }
    return _tabView;
}

- (void)creatModelsWithCount:(NSInteger)count
{
    if (!_modelsArray) {
        _modelsArray = [NSMutableArray new];
    }
    
    NSArray *iconImageNamesArray = @[@"9358d",
                                     @"9358d",
                                     @"9358d",
                                     @"9358d",
                                     @"9358d",
                                     @"9358d",
                                     @"9358d",
                                     @"9358d",
                                     @"9358d"
                                     ];
    
    NSArray *textArray = @[@"当你的 a期处于这种模式下，否则在大屏上会显得字大，内容少，容易遭到用户投诉。但是建议不要长期处于这种模式下，否则在大屏上会显得字大，内容少，容易遭到用户投诉。",
                           @"然后等比例拉则在大屏上会显得字大长期处于这种模式下，否则在大屏上会显得字大，内容少这种情况下对界面不会",
                           @"长期处于容少，容易遭到用户投诉。",
                           @"但是建议不处于这种模式下，否则在大屏上会显得字大，内容少，容易遭到用户投诉。",
                           @"屏幕宽度返，否显，容易遭到用户投诉。但是建议不要长期处于这种模式下，否则在大屏上会显得字大，内容少，容易遭到用户投诉。"
                           ];
    
    for (int i = 0; i < count; i++) {
        
        int nameRandomIndex = arc4random_uniform(5);
        
        DemoVC7Model *model = [DemoVC7Model new];
        model.title = textArray[nameRandomIndex];
        model.iconImagePath = iconImageNamesArray[arc4random_uniform(9)];
        
        int random = arc4random_uniform(1);
        if (random <= 8) {
            NSMutableArray *temp = [NSMutableArray new];
            
            int randomImagesCount = arc4random_uniform(9);
            for (int i = 0; i < randomImagesCount; i++) {
                int randomIndex = arc4random_uniform(9);
                NSString *text = iconImageNamesArray[randomIndex];
                [temp addObject:text];
            }
            model.imagePathsArray = [temp copy];
        }
        [self.modelsArray addObject:model];
    }
}

-(void)setBottomView{
    
    BVBottomView *bottomView = [[BVBottomView alloc]init];
    [self.view addSubview:bottomView];
    [bottomView setFrame:CGRectMake(0, ScreenH-64-40, ScreenW, ScreenH-(ScreenH-40))];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
